package day001;

public class Code01_SelectionSort {

    public static void selectionSort(int[] arr){
        if(arr == null || arr.length < 2){
            return ;
        }

        int n = arr.length;
        for(int i = 0; i < n -1 ; i++){
            for(int j = i+1; j < n; j++){
                if(arr[i] > arr[j]){
                    swap(arr, i, j);
                }
            }
        }
    }

    public static void swap(int[] arr, int i, int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public static void main(String[] args) {
        int[] arr = {3,2,2,8,6,4,9};
        selectionSort(arr);
        for(int a : arr){
            System.out.println(a);
        }
    }
}
